package com.hycat.mail.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.hycat.mail.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hycat.mail.product.entity.AttrGroupEntity;
import com.hycat.mail.product.service.AttrGroupService;
import com.hycat.mail.common.utils.PageUtil;
import com.hycat.mail.common.utils.R;



/**
 * 属性分组
 *
 * @author lzhycat
 * @email 2680628835@qq.com
 * @date 2022-07-16 19:53:30
 */
@RestController
@RequestMapping("/product/attrgroup")
public class AttrGroupController {
    @Autowired
    private AttrGroupService attrGroupService;

    @Autowired
    private CategoryService categoryService;

    /**
     * catelogId分页
     */
    @GetMapping("/list/{catelogId}")
    public R list(@RequestParam Map<String, Object> params,@PathVariable Long catelogId){
        PageUtil page = attrGroupService.queryPage(params, catelogId);
        return R.ok().put("page", page);
    }

    /**
     * 父子三级路径
     */
    @GetMapping("/categoryPath/{attrGroupId}")
    public R delete(@PathVariable Long attrGroupId){
        List<Long> categoryPath = categoryService.categoryPath(attrGroupId);

        return R.ok().put("categoryPath", categoryPath);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{attrGroupId}")
    public R info(@PathVariable("attrGroupId") Long attrGroupId){
		AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId);

        return R.ok().put("attrGroup", attrGroup);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrGroupEntity attrGroupEntity){
		attrGroupService.save(attrGroupEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrGroupEntity attrGroup){
		attrGroupService.updateById(attrGroup);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrGroupIds){
		attrGroupService.removeByIds(Arrays.asList(attrGroupIds));

        return R.ok();
    }
}
